<template>
  <div class="hljs">
    <el-form :model="dataFrom"
             size="small"
             ref="dataForm"
             :rules="dataFormRules"
             label-width="260px">
      <div class="system">语音配置</div>
      <el-form-item label="代理服务器IP" prop="proxyIp">
        <el-input v-model="dataFrom.proxyIp " placeholder="请输入代理服务器IP"></el-input>
      </el-form-item>
      <el-form-item label="代理服务器端口" prop="proxyPort">
        <el-input v-model="dataFrom.proxyPort " placeholder="请输入代理服务器端口"></el-input>
      </el-form-item>
      <el-form-item label="语音电话接口服务器url" prop="voiceServiceUrl">
        <el-input v-model="dataFrom.voiceServiceUrl " placeholder="请输入语音电话接口服务器url"></el-input>
      </el-form-item>
      <el-form-item label="语音接口回传结果SFTP地址" prop="voiceSftpHost">
        <el-input v-model="dataFrom.voiceSftpHost" placeholder ="请输入语音接口回传结果SFTP地址"></el-input>
      </el-form-item>
      <el-form-item label="语音接口回传结果SFTP端口" prop="voiceSftpPort">
        <el-input v-model="dataFrom.voiceSftpPort " placeholder="请输入语音接口回传结果SFTP端口"></el-input>
      </el-form-item>
      <el-form-item label="语音接口服务器登录用户" prop="voiceSftpUser">
        <el-input v-model="dataFrom.voiceSftpUser" placeholder="请输入语音接口服务器登录用户"></el-input>
      </el-form-item>
      <el-form-item label="语音接口服务器登录密码" prop="voiceSftpPwd">
        <el-input v-model="dataFrom.voiceSftpPwd" placeholder="请输入语音接口服务器登录密码"></el-input>
      </el-form-item>
      <el-form-item label="语音接口回传结果SFTP存储文件路径" prop="voiceSftpPath">
        <el-input v-model="dataFrom.voiceSftpPath" placeholder="请输入语音接口回传结果SFTP存储文件路径"></el-input>
      </el-form-item>
      <el-form-item label="语音接口回传结果SFTP存储文件编码" prop="voiceSftpEncode">
        <el-input v-model="dataFrom.voiceSftpEncode" placeholder="请输入语音接口回传结果SFTP存储文件编码"></el-input>
      </el-form-item>
      <el-form-item label="语音接口回传结果corn表达式" prop="voiceSftpCorn">
        <el-input v-model="dataFrom.voiceSftpCorn " placeholder="请输入语音接口回传结果corn表达式"></el-input>
      </el-form-item>
      <el-form-item label="语音告警轮训时间" prop="voiceUpgradeScheduleTime" style="text-align: left">
        <el-input-number v-model="dataFrom.voiceUpgradeScheduleTime"  placeholder="请输入语音告警轮训时间"></el-input-number>
      </el-form-item>
    </el-form>
    <div style="text-align: left">
      <el-button
        :loading="dialogLoading"
        @click="submitForm"
        type="primary"
        size="small">
        保存
      </el-button>
    </div>
  </div>
</template>

<script>
  import {queryConfigVocie} from '@/api/dailyweekly/workflow'
  export default {
    props: {
      dataFrom: {
        type: Object
      },
    },
    data() {
      return {
        dialogLoading: false,
        // dataFrom: {
        //   voiceServiceUrl: '',
        //   voiceSftpHost: '',
        //   voiceSftpPort: '',
        //   voiceSftpUser: '',
        //   voiceSftpPwd: '',
        //   voiceSftpPath: '',
        //   voiceSftpCorn: '',
        //   voiceUpgradeScheduleTime: 10,
        //   voiceSftpEncode: ''
        // },
        dataFormRules: {
          proxyIp: [
            { required: true, message: '请输入代理服务器IP', trigger: 'blur' }
          ],
          proxyPort: [
            { required: true, message: '请输入代理服务器端口', trigger: 'blur' }
          ],
          voiceServiceUrl: [
            { required: true, message: '请输入语音电话接口服务器url', trigger: 'blur' }
          ],
          voiceSftpHost: [
            { required: true, message: '请输入语音接口回传结果SFTP地址', trigger: 'blur' }
          ],
          voiceSftpPort: [
            { required: true, message: '请输入语音接口回传结果SFTP端口', trigger: 'blur' }
          ],
          voiceSftpUser: [
            { required: true, message: '请输入语音接口服务器登录用户', trigger: 'blur' }
          ],
          voiceSftpPwd: [
            { required: true, message: '请输入语音接口服务器登录密码', trigger: 'blur' }
          ],
          voiceSftpPath: [
            { required: true, message: '请输入语音接口回传结果SFTP存储文件路径', trigger: 'blur' }
          ],
          voiceSftpCorn: [
            { required: true, message: '请输入语音接口回传结果corn表达式', trigger: 'blur' }
          ],
          voiceSftpEncode: [
            { required: true, message: '请输入语音接口回传结果SFTP存储文件编码', trigger: 'blur' }
          ]
        }
      }
    },
    // created () {
    //   this.queryConfigDatily()
    // },
    methods: {
      submitForm () {
        this.$refs['dataForm'].validate(valid => {
          if (valid) {
            this.AddConfigDaily()
          }
        })
      },
      async AddConfigDaily () {
        const data = await queryConfigVocie(this.dataFrom, 'post')
        if (data) {
          if (data.code === 200) {
            this.$emit('queryConfigDatily')
            // this.queryConfigDatily()
          }
        }
      },
      async queryConfigDatily () {
        const data = await queryConfigVocie({}, 'get')
        if (data) {
          if (data.code === 200) {
            this.dataFrom = data.data
          }
        }
      }
    }
  }
</script>
